package problem105_300;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author fxk
 * @description 最小栈
 * @date 2020/11/5/005
 */
public class S155 {
    class MinStack {

        Deque<Integer> stack;
        Deque<Integer> minStack;

        /** initialize your data structure here. */
        public MinStack() {
            stack=new LinkedList<>();
            minStack=new LinkedList<>();
            minStack.add(Integer.MAX_VALUE);
        }

        public void push(int x) {
            stack.push(x);
            minStack.push(Math.min(minStack.peek(),x));
        }

        public void pop() {
            stack.pop();
            minStack.pop();
        }

        public int top() {
            return stack.peek();    //不删除栈顶的值
        }

        public int getMin() {
            return minStack.peek();
        }
    }

}
